package com.task.platform.controller;

import com.task.platform.bo.sys.req.EmailReq;
import com.task.platform.common.R;
import com.task.platform.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/email")
public class EmailController {

    @Autowired
    private EmailService emailService;

    /**
     * 发送邮件
     *
     * @param req
     * @return
     */
    //todo 改接口做成防刷的方式，每个ip限制次数，防止被攻击
    @PostMapping("/sendLoginOrRegisterEmail")
    public R<String> sendLoginOrRegisterEmail(@RequestBody EmailReq req) {
        emailService.sendSimpleEmail(req.getEmail(), req.getType());
        return R.success();
    }

    /**
     * 验证码
     *
     * @param req
     * @return
     */
    //todo 改接口做成防刷的方式，每个ip限制次数，防止被攻击
    @PostMapping("/verifyEmailCode")
    public R<String> verifyEmailCode(@RequestBody EmailReq req) {
        String jwt = emailService.verifyEmailCode(req.getEmail(), req.getVerifyCode());
        return R.success(jwt);
    }
}
